﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using G15_Agent.Models.ViewModels;
using G15_Agent.Models.Airplane;
using G15_Agent.Helpers.ServiceHelpers;

namespace G15_Agent.Controllers
{
    public class AirplaneController : Controller
    {
        // gọi ws để lấy về các danh sách
        // loại vé
        // các sân bay đi
        // các sân bay đến

        public ActionResult Index()
        {
            List<SelectListItem> result = new List<SelectListItem>();
            foreach( var service in ServiceFactory.Airplane)
            {
                result.Add(new SelectListItem
                {
                    Value = service.ServiceID,
                    Text = service.ToString()
                });
            }
            return View(result);            
        }

        //public ActionResult AirplaneSearch(string serviceID)
        //{
        //    AirplaneSearchViewModel model = new AirplaneSearchViewModel();
        //    model.serviceID = serviceID;
        //    var service = ServiceFactory.Airplane.FirstOrDefault(m => m.ServiceID.Equals(serviceID));
            
        //    List<SanBay> listSanBayDi = service.GetDepartAirport();
        //    List<SanBay> listSanBayDen = service.GetArrivalAirport();
        //    List<LoaiVe> listLoaiVe = service.GetTicketType();
        //    if (listSanBayDi != null && listLoaiVe != null && listLoaiVe != null)
        //    {
        //        model.dsDiemDi = model.GetAirportSelectList(listSanBayDi);
        //        model.dsDiemDen = model.GetAirportSelectList(listSanBayDen);
        //        model.dsLoaiVe = model.GetTicketSelectList(listLoaiVe);
        //    }
        //    else
        //    {
        //        return View();
        //    }

        //    model.tgDi = System.DateTime.Today;
        //    model.tgDen = System.DateTime.Today;

        //    return View(model);
        //}

        //[HttpPost]
        //public ActionResult AirplaneSearch(AirplaneSearchViewModel model)
        //{
        //    TempData["AirplaneSearchViewModel"] = model;
        //    return RedirectToAction("AirplaneList", new { serviceID = model.serviceID});
        //}

        //[OutputCache(Duration = 3600, VaryByParam = "none")]
        //public ActionResult AirplaneList(string serviceID)
        //{
        //    AirplaneSearchViewModel model = (AirplaneSearchViewModel)TempData["AirplaneSearchViewModel"];
        //    AirplaneListViewModel result = new AirplaneListViewModel();
        //    result.serviceID = model.serviceID;
        //    var service = ServiceFactory.Airplane.FirstOrDefault(m => m.ServiceID.Equals(model.serviceID));
        //    List<ChuyenBay> dsChuyenBay = service.SearchForTicket(
        //        model.slNho, 
        //        model.slLon, 
        //        model.type, 
        //        model.tgDi, 
        //        model.tgDen, 
        //        model.typeTrip, 
        //        model.maDiemDi, 
        //        model.maDiemDen);

        //    if (dsChuyenBay != null)
        //    {
        //        result.dsChuyenBay = dsChuyenBay;
        //    }
        //    else
        //    {
        //        result.dsChuyenBay = new List<ChuyenBay>();
        //        for (int i = 0; i < 15; i++)
        //        {
        //            result.dsChuyenBay.Add(new ChuyenBay
        //            {
        //                maChuyenBay = i.ToString(),
        //                loaiChuyen = (i % 2) == 0 ? "Mot Chieu" : "Khu Hoi",
        //                ngayKhoiHanh = model.tgDi.ToShortDateString(),
        //                ngayVe = model.tgDen.ToShortDateString(),
        //                giaVe = i % 4 * 1000000,
        //                donViTien = "VNĐ",
        //                gioDen = System.DateTime.Now.ToShortTimeString(),
        //                gioDi = System.DateTime.Now.ToShortTimeString(),
        //                maSanBayDi = model.maDiemDi,
        //                maSanBayDen = model.maDiemDen,
        //            });
        //        }
        //    }

        //    return View(result);
        //}

        //[OutputCache(Duration = 3600, VaryByParam = "none")]
        //public ActionResult AirplaneSelect(string serviceID, string id, int soLuong)
        //{
        //    AirplaneListViewModel model = (AirplaneListViewModel)TempData["DanhSachChuyenBay"];
        //    AirplaneBookingViewModel viewModel = new AirplaneBookingViewModel();
        //    viewModel.chuyenBay = model.dsChuyenBay.FirstOrDefault(m => m.maChuyenBay.Equals(id));
        //    viewModel.serviceID = model.serviceID;

        //    return View(viewModel);
        //}

        //[HttpPost]
        //public ActionResult AirplaneSelect(string serviceID, string id)
        //{
        //    return View();
        //}

        //public ActionResult AirplaneBooking(string serviceID)
        //{
        //    AirplaneBookingViewModel model = (AirplaneBookingViewModel)TempData["ThongTinChuyenBayDuocChon"];


        //    return View(model);
        //}

        //public ActionResult TestMultiSelect()
        //{
        //    List<SanBay> sanbay = new List<SanBay>();
        //    for (int i=0; i<10; i++)
        //    {
        //        sanbay.Add(new SanBay{
        //            maSanBay = i.ToString("@@@"),
        //            tenSanBay = "Sân bay" + i.ToString()
        //        });
        //    }
        //    var selected = sanbay.Take(3);
            
        //    var model = new MultiSelectList(sanbay, "maSanBay", "tenSanBay", selected);
        //    return View(model);
        //}

    }
}
